layui.use(['form', 'jquery'], function () {
    const form = layui.form,
        $ = layui.jquery;

    const id = sessionStorage.getItem("dailyId");
    const userCode = localStorage.getItem("loginUserCode");
    findById(id);

    /**
     * 查询单个
     * @param id
     */
    function findById(id) {
        let result = commonAjax(DAILY_APP_URL+'/daily/findById', {id: id}, 'get');
        setData(result.data);
    }

    /**
     * 赋值
     */
    function setData(data) {
        $('#id').val(data.id);
        $('#userCode').val(data.userCode);
        $('#username').val(data.username);
        $('#title').val(data.title);
        $('#dailyTime').val(data.dailyTime);
        $('#headMaster').val(data.headMaster);
        $('#coach').val(data.coach);
        $('#studyContent').val(data.studyContent);
        $('#harvest').val(data.harvest);
        $('#shortage').val(data.shortage);
        form.render();
    }

    /**
     * 判断当前登录用户是否是教练用户
     */
    if (userCode !== undefined && userCode != null && userCode !== '') {
        let result = commonAjax(AUTH_SERVER_URL+'/userRoleRelation/isCoach', {userCode: userCode}, 'get');
        if (result.code === 200) {
            //将日报状态修改为已查看
            commonAjax(DAILY_APP_URL+'/daily/showed',{id:id},'get');
        }
    }

});